package com.lanchetech.user.controller;

import com.lanchetech.bean.dto.*;
import com.lanchetech.bean.request.PageReq;
import com.lanchetech.bean.response.BasePageResp;
import com.lanchetech.bean.response.ResultData;
import com.lanchetech.bean.vo.*;
import com.lanchetech.entity.LotteryRecord;
import com.lanchetech.entity.User;
import com.lanchetech.user.service.LotteryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.*;

@Api(value = "抽奖管理接口", tags = "抽奖管理接口")
@RequestMapping("/api/lottery")
@RestController
public class LotteryController {

    @Autowired
    LotteryService lotteryService;

    @ApiOperation("获取抽奖活动详情")
    @GetMapping("/getLotteryByType")
    public ResultData<LotteryInfoVO> getLotteryByType(@AuthenticationPrincipal User user, @RequestParam("type") Byte type) {
        return lotteryService.getLotteryByType(user, type);
    }

    @ApiOperation(value = "获取抽奖记录分页 弃用",notes = "筛选条件 status, name")
    @PostMapping("/getLotteryRecordPage")
    public ResultData<BasePageResp<LotteryRecordVO>> getLotteryRecordPage(@RequestBody PageReq req) {
        return lotteryService.getLotteryRecordPage(req);
    }

    @ApiOperation("参与抽奖活动")
    @PostMapping("/createLotteryRecord")
    public ResultData<CreateLotteryRecordVo> createLotteryRecord(@RequestBody LotteryDto lotteryDto) {
        return lotteryService.createLotteryRecord(lotteryDto);
    }

    @ApiOperation("填写收货地址 弃用")
    @GetMapping("/createCoinOrderWithAddress")
    public ResultData<Long> createCoinOrderWithAddress(@RequestParam("lotteryRecordId") Long lotteryRecordId, @RequestParam("addressId") Long addressId) {
        return lotteryService.createCoinOrderWithAddress(lotteryRecordId, addressId);
    }

    @ApiOperation("奖品列表 新版")
    @GetMapping("/lotteryInfo")
    public ResultData<RestLotteryInfoVo> lotteryInfo(){
        return lotteryService.lotteryInfo();
    }

    @ApiOperation("中奖人名单 新版")
    @GetMapping("/lotteryWinners")
    public ResultData<LotteryWinnersVo> lotteryWinners(LotteryWinnersDto lotteryWinnersDto){
        return lotteryService.lotteryWinners(lotteryWinnersDto);
    }

    @ApiOperation("中奖订单详情 新版")
    @GetMapping("/lotteryOrder")
    public ResultData<LotteryOrderVo> lotteryOrder(LotteryOrderDto lotteryOrderDto){
        return lotteryService.lotteryOrder(lotteryOrderDto);
    }

    @ApiOperation("中奖记录 新版")
    @GetMapping("/lotteryNewRecord")
    public ResultData<LotteryNewRecordVo> lotteryNewRecord(LotteryNewRecordDto LotteryNewRecordDto){
        return lotteryService.lotteryNewRecord(LotteryNewRecordDto);
    };

    @ApiOperation("新增收货地址 新版")
    @PostMapping("/lotteryNewRecord")
    public ResultData addDeliveryAddress(@RequestBody AddDeliveryAddressDto addDeliveryAddressDto){
        return lotteryService.addDeliveryAddress(addDeliveryAddressDto);
    }

    @ApiOperation("店铺奖品 新版")
    @GetMapping("/shopPrize")
    public ResultData<ShopPrizeVo> shopPrize(ShopPrizeDto shopPrizeDto){
        return lotteryService.shopPrize(shopPrizeDto);
    }
}
